package com.xiaochi.wx.handler;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

/**
 * 微信类型工厂类
 * @author zqx
 * @since 2024/8/31
 */
@Component
public class WxChatMsgFactory implements InitializingBean {

    @Resource
    List<WxChatMsgHandler> wxMsgHandlerList;

    Map<WxchatMsgTypeEnum,WxChatMsgHandler> wxMsgHandlerMap = new HashMap<>();

    public WxChatMsgHandler getMsgTypeHandler(String msgType){
        WxchatMsgTypeEnum wxMsgType = WxchatMsgTypeEnum.getByMsgType(msgType);
        return wxMsgHandlerMap.get(wxMsgType);
    }


    @Override
    public void afterPropertiesSet() throws Exception {
        for (WxChatMsgHandler wxChatMsgHandler : wxMsgHandlerList){
            wxMsgHandlerMap.put(wxChatMsgHandler.getMsgType(),wxChatMsgHandler);
        }
    }
}
